#include <stdio.h>

int s,a,i,b;
main (){
	
	scanf ("%d",&a);
	if (a<=9){
		for (i=1;i<=a;i++){
			
			scanf ("%ld",&b);
			if (b<=999999999){
				
				int c=b/100000000;
				
				int d=b/10000000-10*c;
				
				int e=b/1000000-100*c-10*d;
				
				int f=b/100000-1000*c-100*d-10*e;
				
				int g=b/10000-10000*c-1000*d-100*e-10*f;
				
				int h=b/1000-100000*c-10000*d-1000*e-100*f-10*g;
				
				int j=b/100-1000000*c-100000*d-10000*e-1000*f-100*g-10*h;
				
				int k=b/10-10000000*c-1000000*d-100000*e-10000*f-1000*g-100*h-10*j;
				
				int l=b-100000000*c-10000000*d-1000000*e-100000*f-10000*g-1000*h-100*j-10*k;
				
				s=c+d+e+f+g+h+j+k+l;
				printf ("%d\n",s);
			}
		}
	}
}
